﻿/*!	@file	r_window_Qt.cpp
	@brief	Qt基底
Copyright (c) 2010 Yuya Yamaguchi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#include "r_window_Qt.h"
#if defined(RDEBUG_DEVELOP_BUILD) && R_TARGET_COMMON_WINDOWS

#include <QtCore/QPointer>
#include <QtGui/QMainWindow>

#ifdef _DEBUG
#pragma comment(lib, "QtCored4.lib")
#pragma comment(lib, "QtGuid4.lib")
#pragma comment(lib, "qtmaind.lib")
#else
#pragma comment(lib, "QtCore4.lib")
#pragma comment(lib, "QtGui4.lib")
#pragma comment(lib, "qtmain.lib")
#endif

#include "../../r_debug.h"
#include "../../develop/r_develop_command.h"
#if R_TARGET_UNIQUEIS(R_TARGET_UNIQUE_WINDX11)
#include "r_window_Qtdx11.h"
#else
#endif

cRWindow :: cRWindow()
: qtApp( NULL )
, qtWindow( NULL )
{
	windowWidth		= 1280;
	windowHeight	= 720;
	{
		r_si32 argc = 0;
		qtApp = new QApplication(argc, NULL);
	}
#if R_TARGET_UNIQUEIS(R_TARGET_UNIQUE_WINDX11)
	qtWindow = new cRWindowQtDX11();
#else
	RDEBUG_ASSERTMSG(false, _RST("only directx..."));
#endif
}

cRWindow :: ~cRWindow()
{
	// delete するとassertするんですけど...
#if 0
	delete qtWindow;
	delete qtApp;
#endif
}

QWidget* cRWindow :: getQtWindow( void )const
{
	return qtWindow;
}

void cRWindow :: exec(void)
{
	++loopCount;
	if(qtWindow->preExec() == false){
		RDEBUG_WARRN_MSG(_RST("failed begine loop"));
		return;
	}
	cRDevelopCommand::instance commandInstance;
	qtApp->exec();
	qtWindow->postExec();
}

void cRWindow :: setWindowTitle ( const r_cstr title )
{
	qtWindow->setWindowTitle(title);
}

const r_cstr cRWindow :: getWindoTitle ( void ) const
{
	return qtWindow->getWindoTitle();
}

void* cRWindow :: getWindowhandle ( void ) const
{
	return qtWindow->getWindowhandle();
}

void* cRWindow :: getDeviceContext ( void ) const
{
	return qtWindow->getDeviceContext();
}

r_bool cRWindow :: getHasFocus ( void ) const
{
	return qtWindow->getHasFocus();
}

void cRWindow :: setAppName ( const r_cstr name )
{
	qtWindow->setAppName( name );
}

void cRWindow :: setWindowSize ( r_si32 width, r_si32 height )
{
	windowWidth = width;
	windowHeight = height;
	qtWindow->setWindowSize( width, height );
}

void cRWindow :: setIsFullScreen ( r_bool fullscreen )
{
	qtWindow->setIsFullScreen( fullscreen );
}

#endif

